home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
OTHERCST
/
CHECKDAT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-23
|
3KB
|
111 lines
/********************************************************************************
The following two routines can be used to check the date in any
source code and render the software unusable after that date. This
is useful for developers who want Development/ºeta versions of their
software to die after a specific date.
These routines were designed for use in a System Extension (INIT)
and are used in the following manner.
NOTE: This code is for example purposes only, I avoided some
error-checking on purpose.
main() {
OSErr whoCares = noErr;
RememberA0(); // THINK C stuff
SetUpA4();
asm {
_RecoverHandle
move.l a0, h
}
if (h == nil) {
SysBeep(0);
} else {
DetachResource (h);
}
//
// do my stuff here
//
//
// Now, check to see if we are expired, if so, delete our INIT resource,
// and from now on, we will not load! Works like a charm!
//
If (IsExpired(MONTH, DAY, YEAR) == TRUE) {
whoCares = DeleteResByID('INIT', 128);
}
RestoreA4(); // restore A4
return;
}
That╒s all there is to it! If you have any questions about this code,
send email to the author at any of the following addresses. Enjoy!
America Online : AFL Zobkiw
CompuServe : 70712,515
Internet : 70712.515@compuserve.com
********************************************************************************/
/* ----------------------------------------------------
see if a specific date has passed, if so, return TRUE
---------------------------------------------------- */
Boolean IsExpired(short month, short day, short year)
{
long secs = 0;
long lastsecs = 0;
DateTimeRec date;
GetDateTime(&secs);
date.year = year;
date.month = month;
date.day = day;
date.hour = 0; // the zero hour!
date.minute = 0; // no minutes
date.second = 0; // no seconds
date.dayOfWeek = 0; // ignored
Date2Secs(&date, &lastsecs);
if (secs >= lastsecs) {
return(TRUE);
} else {
return(FALSE);
}
}
/* ----------------------------------------------------
Delete a resource by type/id and update the file
---------------------------------------------------- */
OSErr DeleteResByID(ResType type, short id)
{
Handle h = nil;
OSErr err = noErr;
h = Get1Resource(type, id);
err = ResError(); if (err != noErr) return(err);
if (h != nil) {
RmveResource(h);
err = ResError(); if (err != noErr) return(err);
DisposHandle(h);
err = MemError(); if (err != noErr) return(err);
h = nil;
UpdateResFile(CurResFile());
err = ResError(); if (err != noErr) return(err);
}
return(noErr);
}